home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 21 Ambient Occlusion / Ssao / FrameResource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  3.7 KB  |  116 lines

  1. #pragma once
  2.  
  3. #include "../../Common/d3dUtil.h"
  4. #include "../../Common/MathHelper.h"
  5. #include "../../Common/UploadBuffer.h"
  6.  
  7. struct ObjectConstants
  8. {
  9.     DirectX::XMFLOAT4X4 World = MathHelper::Identity4x4();
  10.     DirectX::XMFLOAT4X4 TexTransform = MathHelper::Identity4x4();
  11.     UINT     MaterialIndex;
  12.     UINT     ObjPad0;
  13.     UINT     ObjPad1;
  14.     UINT     ObjPad2;
  15. };
  16.  
  17. struct PassConstants
  18. {
  19.     DirectX::XMFLOAT4X4 View = MathHelper::Identity4x4();
  20.     DirectX::XMFLOAT4X4 InvView = MathHelper::Identity4x4();
  21.     DirectX::XMFLOAT4X4 Proj = MathHelper::Identity4x4();
  22.     DirectX::XMFLOAT4X4 InvProj = MathHelper::Identity4x4();
  23.     DirectX::XMFLOAT4X4 ViewProj = MathHelper::Identity4x4();
  24.     DirectX::XMFLOAT4X4 InvViewProj = MathHelper::Identity4x4();
  25.     DirectX::XMFLOAT4X4 ViewProjTex = MathHelper::Identity4x4();
  26.     DirectX::XMFLOAT4X4 ShadowTransform = MathHelper::Identity4x4();
  27.     DirectX::XMFLOAT3 EyePosW = { 0.0f, 0.0f, 0.0f };
  28.     float cbPerObjectPad1 = 0.0f;
  29.     DirectX::XMFLOAT2 RenderTargetSize = { 0.0f, 0.0f };
  30.     DirectX::XMFLOAT2 InvRenderTargetSize = { 0.0f, 0.0f };
  31.     float NearZ = 0.0f;
  32.     float FarZ = 0.0f;
  33.     float TotalTime = 0.0f;
  34.     float DeltaTime = 0.0f;
  35.  
  36.     DirectX::XMFLOAT4 AmbientLight = { 0.0f, 0.0f, 0.0f, 1.0f };
  37.  
  38.     // Indices [0, NUM_DIR_LIGHTS) are directional lights;
  39.     // indices [NUM_DIR_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHTS) are point lights;
  40.     // indices [NUM_DIR_LIGHTS+NUM_POINT_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHT+NUM_SPOT_LIGHTS)
  41.     // are spot lights for a maximum of MaxLights per object.
  42.     Light Lights[MaxLights];
  43. };
  44.  
  45. struct SsaoConstants
  46. {
  47.     DirectX::XMFLOAT4X4 Proj;
  48.     DirectX::XMFLOAT4X4 InvProj;
  49.     DirectX::XMFLOAT4X4 ProjTex;
  50.     DirectX::XMFLOAT4   OffsetVectors[14];
  51.  
  52.     // For SsaoBlur.hlsl
  53.     DirectX::XMFLOAT4 BlurWeights[3];
  54.  
  55.     DirectX::XMFLOAT2 InvRenderTargetSize = { 0.0f, 0.0f };
  56.  
  57.     // Coordinates given in view space.
  58.     float OcclusionRadius  = 0.5f;
  59.     float OcclusionFadeStart = 0.2f;
  60.     float OcclusionFadeEnd = 2.0f;
  61.     float SurfaceEpsilon = 0.05f;
  62. };
  63.  
  64. struct MaterialData
  65. {
  66.     DirectX::XMFLOAT4 DiffuseAlbedo = { 1.0f, 1.0f, 1.0f, 1.0f };
  67.     DirectX::XMFLOAT3 FresnelR0 = { 0.01f, 0.01f, 0.01f };
  68.     float Roughness = 0.5f;
  69.  
  70.     // Used in texture mapping.
  71.     DirectX::XMFLOAT4X4 MatTransform = MathHelper::Identity4x4();
  72.  
  73.     UINT DiffuseMapIndex = 0;
  74.     UINT NormalMapIndex = 0;
  75.     UINT MaterialPad1;
  76.     UINT MaterialPad2;
  77. };
  78.  
  79. struct Vertex
  80. {
  81.     DirectX::XMFLOAT3 Pos;
  82.     DirectX::XMFLOAT3 Normal;
  83.     DirectX::XMFLOAT2 TexC;
  84.     DirectX::XMFLOAT3 TangentU;
  85. };
  86.  
  87. // Stores the resources needed for the CPU to build the command lists
  88. // for a frame.  
  89. struct FrameResource
  90. {
  91. public:
  92.     
  93.     FrameResource(ID3D12Device* device, UINT passCount, UINT objectCount, UINT materialCount);
  94.     FrameResource(const FrameResource& rhs) = delete;
  95.     FrameResource& operator=(const FrameResource& rhs) = delete;
  96.     ~FrameResource();
  97.  
  98.     // We cannot reset the allocator until the GPU is done processing the commands.
  99.     // So each frame needs their own allocator.
  100.     Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CmdListAlloc;
  101.  
  102.     // We cannot update a cbuffer until the GPU is done processing the commands
  103.     // that reference it.  So each frame needs their own cbuffers.
  104.     std::unique_ptr<UploadBuffer<PassConstants>> PassCB = nullptr;
  105.     std::unique_ptr<UploadBuffer<ObjectConstants>> ObjectCB = nullptr;
  106.     std::unique_ptr<UploadBuffer<SsaoConstants>> SsaoCB = nullptr;
  107.  
  108.     std::unique_ptr<UploadBuffer<MaterialData>> MaterialBuffer = nullptr;
  109.  
  110.     
  111.  
  112.  
  113.     // Fence value to mark commands up to this fence point.  This lets us
  114.     // check if these frame resources are still in use by the GPU.
  115.     UINT64 Fence = 0;
  116. };